<template>
  <div class="cart_item">
    <div class="cart_column column_1">
      <el-checkbox class="my_el_checkbox" v-model="cart.is_selected" @change="handle_select_change"></el-checkbox>
    </div>
    <div class="cart_column column_2">
      <img :src="cart.course_img" alt="">
      <span><router-link :to="`/courses/${cart.id}`">{{ cart.name }}</router-link></span>
    </div>
    <div class="cart_column column_3">
      <el-select v-model="cart.expire" size="mini" placeholder="请选择购买有效期" class="my_el_select">
        <el-option label="1个月有效" value="30" key="30"></el-option>
        <el-option label="2个月有效" value="60" key="60"></el-option>
        <el-option label="3个月有效" value="90" key="90"></el-option>
        <el-option label="永久有效" value="10000" key="10000"></el-option>
      </el-select>
    </div>
    <div class="cart_column column_4">¥{{ cart.price }}</div>
    <div class="cart_column column_5">
      <el-button type="text" @click="handle_delete">删除</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "CartItem",
  props: ["cart"],
  methods: {
    // 处理选中状态变化
    handle_select_change() {
      this.$emit('select-change', this.cart);
    },
    // 处理删除
    handle_delete() {
      this.$emit('delete', this.cart.id);
    },
  },
};
</script>

<style scoped>
.cart_item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #eee;
}

.cart_column {
  padding: 0 10px;
}

.column_1 {
  width: 50px;
}

.column_2 {
  flex: 1;
  display: flex;
  align-items: center;
}

.column_2 img {
  width: 80px;
  height: 60px;
  margin-right: 20px;
}

.column_3 {
  width: 200px;
}

.column_4 {
  width: 100px;
  text-align: right;
}

.column_5 {
  width: 80px;
  text-align: right;
}
</style>